package a66weding.com.jiehuntong.fragment;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import a66weding.com.jiehuntong.R;


/**
 * Created by Administrator on 2015/12/29.
 */
public abstract class BaseFragment extends Fragment {
    public Activity mActivity;
    public PopupWindow mCommitpop;
    protected IFragmentCallBack callBack;


    /**
     * 当Fragment被创建的时候回调
     * @param savedInstanceState
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.mActivity = (Activity)context;
    }

    /**
     * 当Fragment的View被创建的时候回调这个方法
     * @param inflater
     * @param container
     * @param savedInstanceState
     * @return
     */
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = initView();
        return view;
    }

    public abstract View initView();


    /**
     * 当Activity被创建的时候被回调
     * @param savedInstanceState
     */
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initData();
    }

    public void initData() {

    }

    /**
     * 当子页面需要更新数据时，重写该方法
     *
     */
    public void notifyData(String pageName){

    }


    public void showCommitPopupWindow(View view) {
        // 一个自定义的布局，作为显示的内容
        View contentView = LayoutInflater.from(mActivity).inflate(
                R.layout.pop_tools_wedregister_commit, null);

        mCommitpop = new PopupWindow(contentView,
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
        //点击空白处时，隐藏掉pop窗口
        mCommitpop.setTouchable(true);
        mCommitpop.setTouchInterceptor(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                return true;
            }
        });

        //设置位置
        mCommitpop.showAtLocation(view, Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL,0,0);//设置在屏幕中的显示位置

        // 设置好参数之后再show
        mCommitpop.showAsDropDown(view);

    }


    public void showCommitPopupWindow2(View view) {
        View contentView = LayoutInflater.from(mActivity).inflate(
                R.layout.pop_wrapscreen_commit, null);

        mCommitpop = new PopupWindow(contentView,
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);

        mCommitpop.setTouchable(true);

        mCommitpop.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.whitetranslucenthalf2)));


        contentView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCommitpop.dismiss();
            }
        });


        mCommitpop.setTouchInterceptor(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                mCommitpop.dismiss();
                return true;
            }
        });

        //设置位置
        mCommitpop.showAtLocation(view, Gravity.CENTER|Gravity.CENTER_HORIZONTAL,0,0);//设置在屏幕中的显示位置

        // 设置好参数之后再show
        mCommitpop.showAsDropDown(view);

    }




}
